//2009/08/15 03:04:31
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class SignatureDecorator
{
public:
    string applyDecoration(string name, vector <string> cmd, vector <string> decor)
    {
		string s(name);
		for(int i=0; i<cmd.size(); i++)
		{
			if(cmd[i] == "prepend") s = decor[i] + s;
			else if(cmd[i] == "append") s += decor[i];
			else if(cmd[i] == "surround")
			{
				for(int j=decor[i].size() - 1; j>=0; j--)
				{
					s += decor[i][j];
				}
				s = decor[i] + s;
			}
		}
		return s;
    }
};
